import Vue from 'vue'
import Router from 'vue-router'

//解决一级导航重复点击报错问题
//获取原型对象上的push函数
const originalPush = Router.prototype.push
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router)

/* Layout */
import Layout from '@/layout'


/**
 * Note: 路由配置项
 *
 * hidden: true                   // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true               // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect           // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'             // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * meta : {
    noCache: true                // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'               // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'             // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false            // 如果设置为false，则不会在breadcrumb面包屑中显示
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: (resolve) => require(['@/views/redirect'], resolve)
      }
    ]
  },
  {
    path: '/login',
    component: (resolve) => require(['@/views/login'], resolve),
    hidden: true
  },
  {
    path: '/echarts',
    component: (resolve) => require(['@/views/system/echarts/index'], resolve),
    hidden: true
  },
  {
    path: '/404',
    component: (resolve) => require(['@/views/error/404'], resolve),
    hidden: true
  },
  {
    path: '/401',
    component: (resolve) => require(['@/views/error/401'], resolve),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/index'], resolve),
        name: '首页',
        meta: { title: '首页', icon: 'main', noCache: true, affix: true }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'profile',
        component: (resolve) => require(['@/views/system/user/profile/index'], resolve),
        name: 'Profile',
        meta: { title: '个人中心', icon: 'user' }
      }
    ]
  },
  {
    path: '/dict',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'type/data/:dictId(\\d+)',
        component: (resolve) => require(['@/views/system/dict/data'], resolve),
        name: 'Data',
        meta: { title: '字典数据', icon: '' }
      }
    ]
  },
  {
    path: '/job',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'log',
        component: (resolve) => require(['@/views/monitor/job/log'], resolve),
        name: 'JobLog',
        meta: { title: '调度日志' }
      },
      {
        path: 'index',
        component: (resolve) => require(['@/views/monitor/job/index'], resolve),
        name: 'JobIndex',
        meta: { title: '定时任务' }
      },
    ]
  },
  {
    path: '/gen',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'edit/:tableId(\\d+)',
        component: (resolve) => require(['@/views/tool/gen/editTable'], resolve),
        name: 'GenEdit',
        meta: { title: '修改生成配置' }
      },
      {
        path: 'index',
        component: (resolve) => require(['@/views/tool/gen/index'], resolve),
        name: 'index',
        meta: { title: '修改生成配置' }
      }
    ]
  },
  {
    path: '/event',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'data',
        component: (resolve) => require(['@/views/event/monitor'], resolve),
        name: 'EventData',
        meta: { title: '事件数据分析' },
      },
      {
        path: 'detail',
        component: (resolve) => require(['@/views/event/detail'], resolve),
        name: 'EventDetail',
        meta: { title: '事件详情' },
      },
      {
        path: 'create',
        component: (resolve) => require(['@/views/event/create'], resolve),
        name: 'eventCreate',
        meta: { title: '新建事件' },
      }

    ]
  },
  {
    path: '/opinion',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'detail',
        component: (resolve) => require(['@/views/system/opinion/detail'], resolve),
        name: 'opinionDetail',
        meta: { title: '文章详情' },
      },
      {
        path: 'list',
        component: (resolve) => require(['@/views/system/opinion/list'], resolve),
        name: 'opinionList',
        meta: { title: '舆情列表' },
      },
      {
        path: 'startingMedia',
        component: (resolve) => require(['@/views/system/opinion/startingMedia'], resolve),
        name: 'startingMedia',
        meta: { title: '首发媒体溯源' },
      }

    ]
  },
  {
    path: '/rule',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'list',
        component: (resolve) => require(['@/views/forecast/rule/index'], resolve),
        name: 'RuleList',
        meta: { title: '规则列表' },
      },
      {
        path: 'create',
        component: (resolve) => require(['@/views/forecast/rule/create'], resolve),
        name: 'RuleCreate',
        meta: { title: '新建规则' },
      },
      {
        path: 'update',
        component: (resolve) => require(['@/views/forecast/rule/create'], resolve),
        name: 'RuleUpdate',
        meta: { title: '修改预警规则' },
      },
      {
        path: 'updateDefaultRule',
        component: (resolve) => require(['@/views/forecast/rule/updateDefaultRule'], resolve),
        name: 'UpdateDefaultRule',
        meta: { title: '修改系统预警规则' },
      }
    ]
  },
  {
    path: '/receiver',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'list',
        component: (resolve) => require(['@/views/system/receiver/index'], resolve),
        name: 'receiverList',
        meta: { title: '接收人管理' },
      }
    ]
  },
  {
    path: '/case',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/case/index'], resolve),
        name: 'caseIndex',
        meta: { title: '案例库' },
      },
      {
        path: 'details',
        component: (resolve) => require(['@/views/case/details'], resolve),
        name: 'caseDetails',
        meta: { title: '案例详情' },
      }
    ]
  },
  {
    path: '/favorite',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/favorite/index'], resolve),
        name: 'favoriteIndex',
        meta: { title: '收藏夹' },
      }
    ]
  },




  {
    path: '/template',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'create',
        component: (resolve) => require(['@/views/report/template/create'], resolve),
        name: 'templateCreate',
        meta: { title: '创建模板' },
      }
    ]
  },
  {
    path: '/forecast',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'list',
        component: (resolve) => require(['@/views/forecast/list/index'], resolve),
        name: 'forecastList',
        meta: { title: '舆情预警' },
      }
    ]
  },
  {
    path: '/monitoring',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/monitoring/topic/index'], resolve),
        name: 'monitoringIndex',
        meta: { title: '主题监测' },
      },
      {
        path: 'create',
        component: (resolve) => require(['@/views/monitoring/topic/create'], resolve),
        name: 'create',
        meta: { title: '创建监测主题' },
      },
    ]
  },
  {
    path: '/search',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/search/index'], resolve),
        name: 'searchIndex',
        meta: { title: '云搜索' },
      },
      {
        path: 'retrieval',
        component: (resolve) => require(['@/views/search/retrieval'], resolve),
        name: 'searchRetrieval',
        meta: { title: '互联网信息检索' },
      }
    ]
  },
  {
    path: '/report',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/report/list/index'], resolve),
        name: 'reportIndex',
        meta: { title: '舆情简报' },
      },
      {
        path: 'preview',
        component: (resolve) => require(['@/views/report/previewReport'], resolve),
        name: 'previewReport',
        meta: { title: '报告预览' },
      }
    ]
  },


  {
    path: '/datav',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/datav/index'], resolve),
        name: 'dataV',
        meta: { title: '数据大屏' },
      }
    ]
  },

  {
    path: '/datav/dv1',
    component: (resolve) => require(['@/views/datav/dv1/index'], resolve),
    name: 'dv1',
    meta: { title: '数据大屏' },
    hidden: true
  },
  {
    path: '/datav/dv2',
    component: (resolve) => require(['@/views/datav/dv2/index'], resolve),
    name: 'dv2',
    meta: { title: '数据大屏' },
    hidden: true
  },{
    path: '/datav/dv3',
    component: (resolve) => require(['@/views/datav/dv3/index'], resolve),
    name: 'dv3',
    meta: { title: '数据大屏' },
    hidden: true
  }
]

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
